<template>
  <div class="dashboard-editor-container">

    <panel-group @handleSetLineChartData="handleSetLineChartData" @loading="e => loading = e" />

    <a-row class="chart-wrapper">
      <a-col :span="24">
        <a-skeleton v-if="loading" active :paragraph="{ rows: 4 }" />
        <line-chart v-else :chart-data="lineChartData" />
      </a-col>
    </a-row>
  </div>
</template>

<script>
import PanelGroup from './components/PanelGroup'
import LineChart from './components/LineChart'

export default {
  name: 'DashboardAdmin',
  components: {
    PanelGroup,
    LineChart
  },
  data() {
    return {
      lineChartData: {},
      loading: false
    }
  },
  created() {
    this.lineChartData = {
      countDatas: [],
      xAxisDatas: [],
      bizType: 0
    }
  },
  methods: {
    handleSetLineChartData(title, bizType) {
      if (this.lineChartData.bizType === bizType) {
        return
      }

      if (bizType === 1) {
        this.$api.chart.todayOrderLine().then(res => {
          this.lineChartData = {
            countDatas: res.map(item => item.count),
            xAxisDatas: res.map(item => item.createHour.substring(item.createHour.length - 2) + '时'),
            title: title,
            bizType: bizType
          }
        })
      } else if (bizType === 2) {
        this.$api.chart.monthOrderLine().then(res => {
          this.lineChartData = {
            countDatas: res.map(item => item.count),
            xAxisDatas: res.map(item => item.createDate),
            title: title,
            bizType: bizType
          }
        })
      } else if (bizType === 3) {
        this.$api.chart.todaySmsLine().then(res => {
          this.lineChartData = {
            countDatas: res.map(item => item.count),
            xAxisDatas: res.map(item => item.createHour.substring(item.createHour.length - 2) + '时'),
            title: title,
            bizType: bizType
          }
        })
      } else if (bizType === 4) {
        this.$api.chart.monthSmsLine().then(res => {
          this.lineChartData = {
            countDatas: res.map(item => item.count),
            xAxisDatas: res.map(item => item.createDate),
            title: title,
            bizType: bizType
          }
        })
      }
    }
  }
}
</script>

<style lang="less" scoped>
.dashboard-editor-container {
  padding: 0 12px 12px 12px;
  background-color: rgb(240, 242, 245);
  position: relative;

  .chart-wrapper {
    background: #fff;
    padding: 16px 16px 0;
    margin-top: 32px;
  }
}
</style>
